#!/bin/sh -x
# generates total instruction counts using multiple instr files

EXEC_DIR="$(dirname "$(realpath "$0")")"

base_instructions () {
    "$EXEC_DIR"/filter_collect_instr_files.py \
        --sys "$1" \
            --row "Base" "$1"/dump/*.instr.base \
            --row "Arithmetic" "$1"/dump/*.instr.arith \
            --row "Branch" "$1"/dump/*.instr.branch \
            --row "Jump" "$1"/dump/*.instr.jump \
            --row "Load-Store" "$1"/dump/*.instr.loadstore \
            --row "System" "$1"/dump/*.instr.sys \
                | tee count-"$1"-base
}

ext_instructions () {
    "$EXEC_DIR"/filter_collect_instr_files.py \
        --sys "$1" \
            --row "M ext." "$1"/dump/*.instr.m \
            --row "A ext." "$1"/dump/*.instr.a \
            --row "F/D/Q ext." "$1"/dump/*.instr.f \
            --row "C ext." "$1"/dump/*.instr.c \
            --row "Zicsr ext." "$1"/dump/*.instr.zicsr \
            --row "Zifencei ext." "$1"/dump/*.instr.zifencei \
            --row "Counters" "$1"/dump/*.instr.counters \
            --row "M-mode" "$1"/dump/*.instr.mmode \
            --row "S-mode" "$1"/dump/*.instr.smode \
            --row "H-mode" "$1"/dump/*.instr.hmode \
                | tee count-"$1"-ext
}

base_instructions rv32-freertos
base_instructions rv32-zephyr
base_instructions rv32-glibc-busybox-linux
base_instructions rv32-uclibc-busybox-nommu-linux
ext_instructions rv32-freertos
ext_instructions rv32-zephyr
ext_instructions rv32-glibc-busybox-linux
ext_instructions rv32-uclibc-busybox-nommu-linux
